function AllReady() {
    var mstform = Ext.getCmp("CntChangeM7"); //获取容器
    var tabPanel = Ext.getCmp("tabPanel"); // 获取当前所在 tab 页
    var PhidCnt = mstform.queryById("PhidCnt");
    var PhidPc = mstform.queryById("PhidPc");
    var user_division = mstform.queryById("user_division"); //获取字段---事业部
    var user_regional_center = mstform.queryById("user_regional_center"); //区域中心
    var OriPhidDept = mstform.queryById("OriPhidDept");
    var PhidBuyer = mstform.queryById("PhidBuyer");
    var user_ywlx = mstform.queryById("user_ywlx");
    var user_product_line = mstform.queryById("user_product_line");
    var user_pro_type = mstform.queryById("user_pro_type ");
    var user_business_type = mstform.queryById("user_business_type");
    var user_purchaser = mstform.queryById("user_purchaser");
    var OriCntTitle = mstform.queryById("OriCntTitle");
    var Title = mstform.queryById("Title");
    var toolbar = Ext.getCmp("toolbar");
    toolbar.get("imp").setText("引用采购合同");
    let itemtab_innerCt = null;
    let itemtab_innerCt_tabtool = null;
    let winLock = 0;
    
    if (mstform) {
      if (PhidPc.getValue()) {
        // console.log("PhidPc", PhidPc.getValue());
        execServer("getPtInfoByPhid", { phid: PhidPc.getValue() }, function (res) {
          const datas = JSON.parse(res.data)[0].extendObjects;
          //帮助字段赋值
          // console.log(datas, "datas");
          user_division.setValue(datas.division_phid);
          user_product_line.setValue(datas.midwife_phid);
          user_regional_center.setValue(datas.regional_center_phid);
          BatchBindCombox([user_division]);
          BatchBindCombox([user_product_line]);
          BatchBindCombox([user_regional_center]);
        });
      }
    }
    OriCntTitle.addListener("change", function (args) {
      Title.setValue(OriCntTitle.getValue());
    });
    PhidCnt.addListener("helpselected", function () {
      execServer("getCntInfo", { cnt: PhidCnt.getValue() }, function (res) {
        execServer("getCntInfo", { cnt: PhidCnt.getValue() }, function (res) {
          const datasGetCntInfo = JSON.parse(res.data)[0].extendObjects;
          if (datasGetCntInfo) {
            if (datasGetCntInfo.pc) {
              PhidPc.setValue(datasGetCntInfo?.pc);
              BatchBindCombox([PhidPc]);
            }
            if (datasGetCntInfo.upt) {
              user_pro_type.setValue(datasGetCntInfo.upt);
            }
            if (datasGetCntInfo.ubt) {
              // user_ywlx.setValue(datasGetCntInfo.ubt);
              // BatchBindCombox([user_ywlx]);
            }
            if (datasGetCntInfo.up) {
              user_purchaser.setValue(datasGetCntInfo.up);
              BatchBindCombox([user_purchaser]);
            }
          }
        });
      });
    });
    PhidPc.addListener("change", function (args) {
      if (PhidPc.getValue()) {
        execServer("getPtInfoByPhid", { phid: PhidPc.getValue() }, function (res) {
          const datas = JSON.parse(res.data)[0].extendObjects;
          //帮助字段赋值
          // console.log(datas, "datas");
          user_division.setValue(datas.division_phid);
          user_product_line.setValue(datas.midwife_phid);
          user_regional_center.setValue(datas.regional_center_phid);
          BatchBindCombox([user_division]);
          BatchBindCombox([user_product_line]);
          BatchBindCombox([user_regional_center]);
        });
        if (!PhidCnt.getValue()) return;
        execServer("getCntMInfoByPhid", { phid: PhidCnt.getValue() }, function (res) {
          try {
            const datasGetCntMInfoByPhid = JSON.parse(res.data)[0].extendObjects;
            //帮助字段赋值
            // console.log(datasGetCntMInfoByPhid, "getCntMInfoByPhid");
            OriPhidDept.setValue(datasGetCntMInfoByPhid.dept_phid);
            BatchBindCombox([OriPhidDept]);
            // user_gys.setValue(datasGetCntMInfoByPhid.supply_id);
            // BatchBindCombox([user_gys]);
          } catch (error) {}
        });
      }
    });
    var dgrid = Ext.getCmp("CntChangeD7");
    var dstore = dgrid.store;
  
    dgrid.addListener("edit", function (editor, e) {
      var record = e.record;
      if (e.originalValue == e.value) {
        return;
      }
      try {
        if (record.data.QtyNew > record.data.QtyOld) {
          record.set("QtyNew", record.data.QtyOld);
          Ext.Msg.alert("提示", "新采购数量不能大于原采购数量");
        }
      } catch (error) {
        // console.error(error);
      }
    });
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
      getCntPtypeparam();
      dstore.on("datachanged", async function (dstore, eOpts) {
        const records = dstore.getRange();
        for (const record of records) {
          try {
            if (record.data.QtyNew > record.data.QtyOld) {
              record.set("QtyNew", record.data.QtyOld);
              Ext.Msg.alert("提示", "新采购数量不能大于原采购数量");
            }
          } catch (error) {
            // console.error(error);
          }
        }
      });
    }
  
    //根据id获取原合同条款信息
    function getCntPtypeparam() {
      console.log("getCntPtypeparam");
      const phidCntV = PhidCnt.getValue();
  
      if (!phidCntV) return;
  
      tabPanel.setActiveTab(1);
      var dgrid3 = Ext.getCmp("itemtab").items.items[0].items.items[0];
  
      execServer("getCntPtypeparam", { phid_cnt: phidCntV }, function (res) {
        console.log(res);
        if (res.count > 0) {
          const datas = JSON.parse(res.data);
          // console.log(datas);
          var gridArr = [];
          var gridCount = res.count;
          for (var i = 0; i < gridCount; i++) {
            var gridObj = {};
            gridObj.PhidRelItem = datas[i].extendObjects.phid;
            gridObj.PhidItem = datas[i].extendObjects.phid_item;
            gridObj.PhidItemNew = datas[i].extendObjects.phid_item_new;
            gridObj.Name = datas[i].extendObjects.name;
            gridObj.NameNew = datas[i].extendObjects.name_new;
            // gridObj.oper_flg = datas[i].extendObjects.oper_flg;
            gridArr.push(gridObj);
          }
          dgrid3.store.add(gridArr);
          // console.log(gridArr);
        } else {
          console.log("功能扩展暂无数据");
        }
      });
  
      tabPanel.setActiveTab(0);
    }
  }
  